<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DataGenerator
 *
 * @author mateusz.ledzewicz
 */
class DataGenerator {
    
    const sourceFolder          = 'training';
    const ext                   = '.data';
    const inNormal              = 'Normal';
    const inTime                = 'Time';
    
    const outGrowth             = 'Growth';
    const outGrowthBasic        = 'GrowthBasic';
    const outValue              = 'Value';
    const outDummyTrend         = 'DummyTrend';
    const outAvgTrend           = 'AvgTrend';
    
    const typeGPW               = 'gpw';
    const typeYahoo             = 'yahoo';
    
    const endLine               = "\n";
    
    
    protected $typeIn;
    protected $typeOut;
    
    protected $dataIn;
    protected $dataOut;
    protected $config;
    
    protected $number_in;
    protected $number_out;


    public static function generateDataIn($inType, $config, $numberOfData, $params, $currency, $days)
    {
        $offset = (isSet($config['offset']) && !empty($config['offset'])) ? $config['offset'] : 30;
        if($config['type'] == 'gpw')
        {
            $dataIn = new $inType($config['isin'], $config['dateTo'], AbstractDataIN::GPW, $numberOfData, $days, $params, $offset, $currency);
           
        } else if($config['type'] == 'yahoo')
        {
             $dataIn = new $inType($config['isin'], $config['dateTo'], AbstractDataIN::Yahoo,$numberOfData, $days, $params, $offset, $currency);
        }
        return $dataIn;
        
        
    }
    
    public static function generateDataOut($outType, $paramsOut, $dataIn)
    {
       $dataOut = new $outType($dataIn, $paramsOut);
       return $dataOut;
    }
    
    
    
    
    public function __construct($inType, $outType, $config) {
        $this->typeIn = $inType;
        $this->typeOut = $outType;
        $this->config = $config;
    }
    
    public function generateData($numberOfData, $paramsIn, $paramsOut, $days){
        $currency = null;
        $offset = max(array(Param::getOffset($paramsIn), $paramsOut->getOffset()));
        
        $this->config['offset'] = $offset;
        foreach($paramsIn as $param){
            if($param->param == Param::currency){
                $currency = $param->value;
                break;
            }
        }
        
        $this->dataIn = self::generateDataIn($this->typeIn, $this->config, $numberOfData, $paramsIn, $currency, $days);
        $this->dataOut = self::generateDataOut($this->typeOut, $paramsOut, $this->dataIn);
    }
    
    public function AddFrankIn()
    {
        $this->dataIn ->AddMoney(GetMoney::CHF);
    }
    
    public function AddEuroIn()
    {
        $this->dataIn ->AddMoney(GetMoney::EUR);
    }
    
    public function AddUSDIn()
    {
        $this->dataIn ->AddMoney(GetMoney::USD);
    }
    
    public function generateFile($name)
    {
        $this->number_in = count($this->dataIn->getData()[0]);
        $this->number_out = count($this->dataOut->getData()[0]);
        $content = count($this->dataIn->getData()).' '.count($this->dataIn->getData()[0]).' '.count($this->dataOut->getData()[0]).self::endLine;
        
        $trainingData = array_reverse(array_map(null, $this->dataIn->getData(), $this->dataOut->getData())); 
        
        foreach($trainingData as $dataSet)
        {
            foreach($dataSet[0] as $in)
            {
                $content .= $in.' ';
            }
            
            $content .= self::endLine;
            
            foreach($dataSet[1] as $out)
            {
                $content .= $out.' ';
            }
            
            $content .= self::endLine;  
        }
       
        file_put_contents($name, $content);
        
    }
    
    public function getNumberIn()
    {
        return $this->number_in;
    }
    
    public function getNumberOut()
    {
        return $this->number_out;
    }
    
    
    
    
}

?>
